package org.beetl.sql.core.db;

import java.lang.annotation.Annotation;
import java.util.List;

import org.beetl.sql.annotation.entity.AssignID;
import org.beetl.sql.annotation.entity.AutoID;
import org.beetl.sql.annotation.entity.SeqID;
import org.beetl.sql.clazz.kit.BeanKit;
import org.beetl.sql.core.ConnectionSource;
import org.beetl.sql.core.meta.LegacySchemaMetadataManager;
import org.beetl.sql.core.meta.MetadataManager;

public class LegacyDamengStyle extends DamengStyle{
	
	@Override
    public int getIdType(Class c,String idProperty) {
                List<Annotation> ans = BeanKit.getAllAnnotation(c, idProperty);
        int idType = DBType.ID_AUTO; //默认是自增长
        for (Annotation an : ans) {
            if (an instanceof AutoID) {
                idType = DBType.ID_AUTO;
                break;// 优先
            } else if (an instanceof SeqID) {
                idType = DBType.ID_SEQ;
            } else if (an instanceof AssignID) {
                idType = DBType.ID_ASSIGN;
            }else if(an instanceof org.beetl.sql.core.annotatoin.AssignID) {
				idType = DBType.ID_ASSIGN;
			} else if(an instanceof org.beetl.sql.core.annotatoin.SeqID) {
				idType = DBType.ID_SEQ;
			} else if(an instanceof org.beetl.sql.core.annotatoin.AutoID) {
				idType = DBType.ID_AUTO;
				break;
			}
        }
        return idType;
    }
	
	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs) {
		metadataManager = new LegacySchemaMetadataManager(cs, this);
		return metadataManager;
	}

	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs, String defaultSchema, String defalutCatalog) {
		metadataManager = new LegacySchemaMetadataManager(cs, defaultSchema, defalutCatalog, this);
		return metadataManager;
	}

}
